<#assign menu="price">
<#assign submenu="add_price">
<#include "../../manage/head.ftl">

<link rel="stylesheet" type="text/css"
      href="${BASE_PATH}/static/manage/css/select2.css"/>
<!--main content start-->
<section id="main-content">
    <section class="wrapper">
        <!-- page start-->

        <form id="add_price_form" class="form-horizontal" action="${BASE_PATH}/manage/price/add.json"
              autocomplete="off" method="post"
              enctype="multipart/form-data">
            <input type="hidden" name="goodsId" id="goodsId">
            <div class="row">
                <div class="col-lg-12">
                    <section class="panel">
                        <header class="panel-heading">
                            添加价格
                        </header>
                        <div class="panel-body">

                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">商品名</label>
                                <div class="col-sm-2 col-sm-2 control-label">
                                    <div class="col-sm-10">

                                        <input type="text" style="font-size:15px;width: 300px;" class="select2 select2-offscreen"  tabindex="-1"
                                               placeholder="商品名字" id="goods">
                                        </input>

                                    </div>
                                </div>

                            </div>


                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">尺寸</label>
                                <div class="col-sm-2 col-sm-2 control-label">
                                    <div class="col-sm-10">
                                        <input type="text" style="font-size:15px;width: 300px;" class="form-control"
                                               name="size"
                                               placeholder="商品尺寸">
                                        </input>
                                    </div>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">价格</label>
                                <div class="col-sm-2 col-sm-2 control-label">
                                    <div class="col-sm-10">
                                        <input type="text" style="font-size:15px;width: 300px;" class="form-control"
                                               name="price"
                                               placeholder="商品价格">
                                        </input>
                                    </div>
                                </div>
                            </div>

                        </div>
                        <div class="form-group">
                            <div class="col-lg-offset-2 col-lg-10">
                                <button class="btn btn-shadow btn-primary" type="submit">发布</button>
                            </div>
                        </div>
                    </section>
                </div>
            </div>


        </form>
    <!-- page end-->
</section>
</section>
<!--main content end-->

<script type="text/javascript" src="${BASE_PATH}/static/manage/js/select2/bootstrap-select.min.js"></script>
<script type="text/javascript" src="${BASE_PATH}/static/manage/js/select2/select2.js"></script>
<script type="text/javascript" src="${BASE_PATH}/static/manage/js/select2/select2_locale_zh-CN.js"></script>
<script type="text/javascript">
    $(function () {
        $('#add_price_form').ajaxForm({
            dataType: 'json',
            success: function (data) {
                if (data.result) {
                    bootbox.alert("保存成功，将刷新页面", function () {
                        window.location.reload();
                    });
                } else {
                    showErrors($('#add_price_form'), data.errors);
                }
            }
        });

    });




    $("#goods").select2({
        placeholder:"请选择商品",
        minimumInputLength: 1,
        id: function (obj) {
            return obj.id;
        },
        ajax: {
            url: "${BASE_PATH}/manage/goods/search.json",

            quietMillis: 1000,
            data: function (term, page) {
                return {
                    name: term

                };
            },

            cache: true,
            results: function (data, page) { // parse the results into the format expected by Select2.
//                console.log(data);
                // since we are using custom formatting functions we do not need to alter remote JSON data
                return {
                    results: jQuery.parseJSON(data.t)
                };
            }
        },


        formatResult: movieFormatResult,
        formatSelection: function (goods) {

            selectedGoods = goods;
            return goods.name;

        },
        dropdownCssClass: "bigdrop", // apply css that makes the dropdown taller
        escapeMarkup: function (m) {
            return m;
        } // we do not want to escape markup since we are displaying html in results
    });

    var selectedGoods;
    function movieFormatResult(goods) {
        $("#goodsId").val(goods.id);
        var markup = "<table class='movie-result'  style='width: 100%;height: 100%;text-align: center;' ><tr>";
        markup += "<td valign='top' >" + goods.name + "</td>";
        markup += "</tr></table>"
        return markup;
    }


</script>
<#include "../../manage/foot.ftl">